package com.dxb.test.spring;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@ConditionalOnProperty(name = "com.dxb.test.spring.ConditionalOnImport", havingValue = "true")
@Import(TestBean.class)
@Configuration
public class ConditionalOnImport implements InitializingBean {
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println(this.getClass().getName() + "afterPropertiesSet");
    }

    /**
     * 初始化方法的注解方式  等同与init-method=init
     */
    @PostConstruct
    public void init() {
        System.out.println(this.getClass().getName() + "调用初始化方法....");
    }

    /**
     * 销毁方法的注解方式  等同于destroy-method=destroy
     */
    @PreDestroy
    public void destroy() {
        System.out.println(this.getClass().getName() + "调用销毁化方法....");
    }
}
